﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Spectrum
{
    /// <summary>
    /// 包络函数
    /// </summary>
    public class EnvelopeFunction
    {
        /// <summary>
        /// 平稳段起点
        /// </summary>
        private int t1 { set; get; }

        /// <summary>
        /// 平稳段终点
        /// </summary>
        private int t2 { set; get; }

        /// <summary>
        /// 衰减系数
        /// </summary>
        private double c { set; get; }

        /// <summary>
        /// 获得包络值
        /// </summary>
        /// <param name="time"></param>
        /// <returns></returns>
        public double GetFt(double time)
        {
            if (time < t1) return Math.Pow(time / t1, 2);
            else if (time < t2) return 1;
            else return Math.Exp(-this.c * (time - t2));
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="tmin"></param>
        /// <param name="tmax"></param>
        /// <param name="cFactor"></param>
        public EnvelopeFunction(int tmin, int tmax, double cFactor)
        {
            this.t1 = Math.Min(tmin, tmax);
            this.t2 = Math.Max(tmin, tmax);
            this.c = cFactor;
        }
    }
}
